<!--
 * @FilePath     : /study_code/wangEditor/11-7.html
 * @Description  : Ajax 异步设置内容
 * @Date         : 2025-04-07 23:06:52
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-07 23:08:05
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/@wangeditor/editor/dist/css/style.css" />
    <link rel="stylesheet" href="/wangEditor/common/style.css" />
  </head>
  <body>
    <button id="btn1">异步获取富文本初始内容</button>

    <hr />

    <div id="editor—wrapper">
      <div id="toolbar-container"><!-- 工具栏 --></div>
      <div id="editor-container"><!-- 编辑器 --></div>
    </div>

    <script src="/@wangeditor/editor/dist/index.js"></script>
    <script>
      const { createEditor, createToolbar } = window.wangEditor

      const editorConfig = {
        placeholder: 'Type here...',
      }

      /* const editor = createEditor({
        selector: '#editor-container',
        html: '<p><br></p>',
        config: editorConfig,
        mode: 'default', // or 'simple'
      })

      const toolbarConfig = {}

      const toolbar = createToolbar({
        editor,
        selector: '#toolbar-container',
        config: toolbarConfig,
        mode: 'default', // or 'simple'
      }) */

      // ------------------------------
      btn1.addEventListener(
        'click',
        function () {
          console.log(2, '开始获取数据')
          setTimeout(function () {
            const html = '初始内容'
            console.log(3, '得到数据', html)
            const editor = createEditor({
              selector: '#editor-container',
              html,
              config: editorConfig,
              mode: 'default',
            })
            console.log(4, '执行结束')
          }, 2000)
        },
        false
      )

      console.log(1, '同步代码')
    </script>
  </body>
</html>
